package com.sevenstudio.adu.gasing.state;



import org.andengine.engine.Engine.EngineLock;
import org.andengine.entity.scene.ITouchArea;
import org.andengine.entity.scene.Scene;
import org.andengine.input.touch.TouchEvent;
import org.andengine.input.touch.detector.ClickDetector;
import org.andengine.input.touch.detector.ScrollDetector;
import org.andengine.util.color.Color;

import android.view.KeyEvent;

import com.sevenstudio.adu.gasing.bluetooth.BT_Server_Client;
import com.sevenstudio.adu.gasing.define.GameEngineConfiguration;
import com.sevenstudio.adu.gasing.define.iGameDefines;
import com.sevenstudio.adu.gasing.define.iServer_Data;
import com.sevenstudio.adu.gasing.element.ABackground;
import com.sevenstudio.adu.gasing.element.ARectangle;
import com.sevenstudio.adu.gasing.element.AScene;
import com.sevenstudio.adu.gasing.element.ASound;
import com.sevenstudio.adu.gasing.element.ASprite;
import com.sevenstudio.adu.gasing.element.AStrokeText;
import com.sevenstudio.adu.gasing.element.AText;
import com.sevenstudio.adu.gasing.engine.GameEngine;
import com.sevenstudio.adu.gasing.engine.Menu_Scroll;
import com.sevenstudio.adu.gasing.engine.Utils;

public class State_Select_Player  {

	GameEngine engine;
	AScene aScene;
	static ASprite title_player,  bg_Brown, bg_review, btn_cancel, btn_pilih;
	static ABackground bg_Select; 
	static ASprite[]spr_player = new ASprite[10];
	static ASprite[] btn_menu = new ASprite[3];
	static ASprite[] icon_player = new ASprite[10];
	static AStrokeText aStrokeText;
	ASprite[] spr_shop = new ASprite[iGameDefines.SPRITE_SHOP.length];
	
	static ASprite[] spr_unlock_player = null;
	static ASprite[] spr_lock_player = null;
	
	static ASprite[] img_lock = new ASprite[10];
	
	static ASprite img_point;
	static AText txt_point;
	
	static ASound sfx_slide, sfx_Yes, sfx_No;
	
	static AText txt_review_gasing;
	
	static AText nama_gasing;
	

	Menu_Scroll menu_Scroll_unlock, menu_Scroll_lock, menu_scroll_shop;

	
	static ASprite bg_pointer;
	static ASprite[] pointer = new ASprite[3];
	static ASprite[] hover_pointer = new ASprite[3];
	
	final float SCALE_MINI = 0.8f;
	
	float width = 1f;
	
	int INDEX_I, INDEX_J;
	
	static ARectangle rec;

	private boolean isWaiting = false;	
	
	public State_Select_Player(GameEngine engine)
	{

		Utils.TRACE("SP INIT");		
		
		this.engine = engine;
		aScene = new AScene(0);
		
		sfx_slide = new ASound(engine, iGameDefines.SFX_SLIDE);
		sfx_Yes = new ASound(engine, iGameDefines.SFX_YES);
		sfx_No = new ASound(engine, iGameDefines.SFX_NO);
				
		
		bg_Brown = new ASprite(engine, iGameDefines.SPRITE_SELECT_PLAYER, iGameDefines.INDEX_BG_MENU);
		bg_Brown.SetPos(State_Main_Activity.CAMERA_WIDTH - bg_Brown.theSprite().getWidth(), State_Main_Activity.CAMERA_HEIGHT - bg_Brown.theSprite().getHeight());
		
		
		bg_review = new ASprite(engine, iGameDefines.SPRITE_SELECT_PLAYER, iGameDefines.INDEX_BG_REVIEW);
		
		btn_cancel = new ASprite(engine, iGameDefines.SPRITE_SELECT_PLAYER, iGameDefines.INDEX_BTN_CANCEL);
		btn_cancel.theSprite().setX(Utils.GetRatioWidth(600));
		
		btn_pilih = new ASprite(engine, iGameDefines.SPRITE_SELECT_PLAYER, iGameDefines.INDEX_BTN_PILIH);
		
		rec = new ARectangle(engine, iGameDefines.RECT_GAME, 6);
		rec.theRect().setAlpha(80);
			
			
		txt_review_gasing = new AText(engine, iGameDefines.TEXT_SELECT_PLAYER, iGameDefines.FONT_1_SMALL, 
				engine.gameFont[iGameDefines.FONT_1_SMALL]);
		
		nama_gasing = new AText(engine, iGameDefines.TEXT_SELECT_PLAYER, 1, engine.gameFont[0] );
		nama_gasing.theText().setPosition(Utils.GetRatioWidth(10), Utils.GetRatioHeight(200));
				
		
			for(int i=0; i < 10; i++)
			{
				spr_player[i] = new ASprite(engine, iGameDefines.SPRITE_SELECT_PLAYER, 1+i);
			}
			
		for(int i=0; i < img_lock.length; i++)
		{
			img_lock[i] = new ASprite(engine, iGameDefines.SPRITE_SELECT_PLAYER, iGameDefines.INDEX_HOVER_POINTER + 3);
		}			

		img_point = new ASprite(engine, iGameDefines.SPRITE_SELECT_PLAYER, iGameDefines.INDEX_HOVER_POINTER + 4);
		txt_point = new AText(engine, iGameDefines.TEXT_SELECT_PLAYER, 2, engine.gameFont[2]);

		for(int i=0; i < iGameDefines.SPRITE_SHOP.length; i++)
		{
			spr_shop[i] = new ASprite(engine, iGameDefines.SPRITE_SHOP, i);
		}
		
		menu_scroll_shop = new Menu_Scroll(engine, sfx_slide.theSound(), State_Main_Activity.CAMERA_WIDTH / 3, spr_shop);
		
		
		for(int j=0; j < iGameDefines.COUNT_ICON_GASING; j++)
		{

					icon_player[j] = new ASprite(engine, iGameDefines.SPRITE_SELECT_PLAYER, j+11);
					
					

		}
		
		
		title_player= new ASprite(engine, iGameDefines.SPRITE_SELECT_PLAYER, iGameDefines.INDEX_TITLE_PILIH_GASING);
	
		
		bg_Select = new ABackground(engine, iGameDefines.SPRITE_SELECT_PLAYER, iGameDefines.INDEX_SELECT_BG);
		
		for(int i=0; i < 3; i++)
		{
			btn_menu[i] = new ASprite(engine, iGameDefines.SPRITE_SELECT_PLAYER, i+iGameDefines.INDEX_MENU_SEECT_PLY);
			btn_menu[i].SetPos((Utils.GetRatioWidth(95 * 2.5f) + (i * btn_menu[i].theSprite().getWidth())), Utils.GetRatioHeight(35));
			
			if(i>0)
			{
				btn_menu[i].setScale(0.8f);
			}
		}
		
		for(int i=0; i < pointer.length; i++)
		{
			pointer[i] = new ASprite(engine, iGameDefines.SPRITE_SELECT_PLAYER, iGameDefines.INDEX_POINTER);
			hover_pointer[i] = new ASprite(engine, iGameDefines.SPRITE_SELECT_PLAYER, iGameDefines.INDEX_HOVER_POINTER + i);
		}
		
		bg_pointer = new ASprite(engine, iGameDefines.SPRITE_SELECT_PLAYER, iGameDefines.INDEX_BG_POINTER);
		
		
		
		aScene.theScene().setOnAreaTouchListener(engine);
		aScene.theScene().setOnSceneTouchListener(engine);
		aScene.theScene().registerTouchArea(btn_cancel.theSprite());
		aScene.theScene().registerTouchArea(btn_pilih.theSprite());
//		aScene.theScene().registerTouchArea(btn_info.theSprite());
	}

	public void Init() 
	{
		
		Utils.TRACE("INIT");
		
		aScene.theScene().detachChildren();
		
		generateProfileGasing();
		
		engine.SetGameScene(aScene);
		engine.SceneAttach(aScene, bg_Brown);
		attachAllPLayer(engine, aScene);
		attachDisplayPlayer(spr_unlock_player);

		attchShop();
		

		engine.SceneAttach(aScene, bg_Select);
		
		
		attachIcon(engine, aScene);
	
		
		for(int i=0; i < 3; i++)
		{
			engine.SceneAttach(aScene, btn_menu[i]);
		}
		
		attachPoint(engine, aScene);
		
		engine.SceneAttach(aScene, nama_gasing);


		engine.SceneAttach(aScene, title_player);
		
				
		attachPointer(engine, aScene);
		
		
		engine.SceneAttach(aScene, rec);
		rec.theRect().setVisible(false);
		
		attachAllReview(engine, aScene);
		

		engine.SetNextMessageState(engine.NextMessageState());

	}
	


	
	

	public void Update() 
	{
		
		if (BT_Server_Client.isClientWaiting && BT_Server_Client.isServerWaiting)
		{
			engine.SetNextMessageState(0);
			engine.SetNextGameState(iGameDefines.GAME_STATE_GAMEPLAY);
		}


		if(menu_Scroll_unlock.getFocus() < spr_unlock_player.length / 3)

		{	
			hover_pointer[0].theSprite().setVisible(true);
			hover_pointer[1].theSprite().setVisible(false);
			hover_pointer[2].theSprite().setVisible(false);
		}
		else if(menu_Scroll_unlock.getFocus() < (int) spr_unlock_player.length / 2 && menu_Scroll_unlock.getFocus() > (int) spr_unlock_player.length / 3)
		{
			hover_pointer[0].theSprite().setVisible(false);
			hover_pointer[1].theSprite().setVisible(true);
			hover_pointer[2].theSprite().setVisible(false);
		}
		else if(menu_Scroll_unlock.getFocus() < spr_unlock_player.length && menu_Scroll_unlock.getFocus() > (int) spr_unlock_player.length / 2)
		{
			hover_pointer[0].theSprite().setVisible(false);
			hover_pointer[1].theSprite().setVisible(false);
			hover_pointer[2].theSprite().setVisible(true);
		}


		for(int i=0; i < spr_unlock_player.length; i++ )

		{
			if(spr_player[i].theSprite().isVisible())
			{
		
				
				
					if(	menu_Scroll_unlock.getFocus() == i)
					{
						icon_player[i].theSprite().setVisible(true);
						nama_gasing.theText().setText(iGameDefines.NAMA_GASING[0][i]);
					
					}
					else 
					{
						icon_player[i].theSprite().setVisible(false);
					
					}
				
			}else {
					icon_player[i].theSprite().setVisible(false);
				
			}
			
//			if(spr_player[1][i].theSprite().isVisible())
//			{	if(menu_Scroll2.getFocus() == i)
//				{
//					icon_player[1][i].theSprite().setVisible(true);
//					nama_gasing.theText().setText(iGameDefines.NAMA_GASING[1][i]);
//				}
//				else 
//				{
//					icon_player[1][i].theSprite().setVisible(false);
//				}
//			}
//			else
//			{
//				icon_player[1][i].theSprite().setVisible(false);
//			}
		}
		
		
		
	}

	
	public void exit() 
	{
		
			final EngineLock lock = engine.getEngine().getEngineLock();
			lock.lock();
			
			bg_Brown.DetachSelf();
			
			detachAllPlayer();
			
			bg_Select.DetachSelf();
			
			for(int i=0; i < 3; i++)
			{
				btn_menu[i].DetachSelf();
			}
			
			
			detachIcon();		
			
			nama_gasing.theText().detachSelf();
			

			
			title_player.DetachSelf();
			
			detachReview();
		
			detachPointer();
			
			for(int i=0; i < iGameDefines.SPRITE_SHOP.length; i++)
			{
				spr_shop[i].DetachSelf();
			}
		
			img_point.DetachSelf();
			txt_point.theText().detachSelf();
			
			lock.unlock();
	}

	
	public void keyBack(int keyCode, KeyEvent event)
	{
		if(keyCode == KeyEvent.KEYCODE_BACK)
		{
			
				if(engine.messageCurrentState ==  iGameDefines.MESSAGE_STATE_UPDATE)
				{
					exit();
				}
				
				if(BT_Server_Client.isBluetooth)
				{
					Utils.toast("Disconected");
					engine.server_Client.sendMessage("disconnect");
					engine.server_Client.stopBTThread();
				}

				engine.SetNextMessageState(0);
				engine.SetNextGameState(iGameDefines.GAME_STATE_MODE);

			
			
		}
	}

	public void SceneTaouch(Scene arg0, TouchEvent arg1)
	{
		menu_Scroll_unlock.onTouchEvent(arg1);
		menu_Scroll_lock.onTouchEvent(arg1);
		menu_scroll_shop.onTouchEvent(arg1);
		
		
		if(arg1.isActionDown() && Utils.IsTouched_Down(btn_menu[0], arg1))
		{


		
		for(int i =0; i < spr_unlock_player.length; i++)
		{
			if(arg1.isActionUp() && Utils.IsTouched_Up(spr_player[i], arg1) 
					&& !bg_review.theSprite().isVisible()
					&& menu_Scroll_unlock.getFocus() == i
					&& spr_unlock_player[i].theSprite().isVisible()
					)
			{

				iServer_Data.INDEX_MC = i;
			}
			
			
		}
		
		}
		
	}
	
	public void onScrollFinish(ScrollDetector pScollDetector, int pPointerID,
			float pDistanceX, float pDistanceY)
	{
	
		
	}
	
	public void onScroll(ScrollDetector pScollDetector, int pPointerID,
			float pDistanceX, float pDistanceY) 
	{
		
			
	}
	

	static void attachAllPLayer(GameEngine engine, AScene aScene)

	{

			
			for(int i=0; i < spr_unlock_player.length; i++)
			{
				engine.SceneAttach(aScene, spr_unlock_player[i]);
				spr_unlock_player[i].theSprite().setVisible(false);
			}
			
			for(int i=0; i < spr_lock_player.length; i++)
			{
				engine.SceneAttach(aScene, spr_lock_player[i]);
				spr_lock_player[i].theSprite().setAlpha(0.5f);
				spr_lock_player[i].theSprite().setVisible(false);
//				img_lock[i].SetPos(Utils.getCenterObjX(spr_lock_player[i].theSprite(), img_lock[i].theSprite()), Utils.getCenterObjY(spr_lock_player[i].theSprite(), img_lock[i].theSprite()));
				
				spr_lock_player[i].theSprite().detachChildren();
				
				spr_lock_player[i].theSprite().attachChild(img_lock[i].theSprite());
			}
		
	}
	
	static void attachUnlockGasing(GameEngine engine, AScene aScene)
	{
		for(int i=0; i < spr_unlock_player.length; i++)
		{
			engine.SceneAttach(aScene, spr_unlock_player[i]);
			
		}
	}
	
	static void detachAllPlayer()
	{

		
		for(int i=0; i < spr_unlock_player.length; i++)
		{
			spr_unlock_player[i].DetachSelf();
		}
		
		for(int i=0; i < spr_lock_player.length; i++)
		{
			spr_lock_player[i].DetachSelf();
			img_lock[i].DetachSelf();
		}
		
	}
	
	static void attachPointer(GameEngine engine, AScene scene)
	{
//<<<<<<< .mine
//		engine.SceneAttach(scene, bg_pointer);
//	
//		bg_pointer.theSprite().detachChildren();
//		
//		for(int i =0; i < pointer.length; i++)
//=======
		engine.SceneAttach(scene, bg_pointer);
	
		bg_pointer.theSprite().detachChildren();
		
		for(int i =0; i < pointer.length; i++)
		{
			pointer[i].SetPos((Utils.GetRatio(45) * i), 0);
			Utils.TRACE("pointer X "+pointer[i].GetX());
		}
		
		
		for(int i=0; i < pointer.length; i++)
		{
			engine.attachParent(bg_pointer, pointer[i]);
			engine.attachParent(bg_pointer, hover_pointer[i]);
			
			if(i > 0 )
			{
				hover_pointer[i].theSprite().setVisible(false);
			}
			
		}
	}
	
	static void detachPointer()
	{
		bg_pointer.DetachSelf();
		
		for(int i =0; i < pointer.length; i++)
		{
			pointer[i].DetachSelf();
			hover_pointer[i].DetachSelf();
		}
		
	
		
	}
	
//	static void detachDisplayAllPlayer()
//	{
//		for(int i=0; i < 1; i++)
//
//		{
//			pointer[i].SetPos((Utils.GetRatio(45) * i), 0);
//			Utils.TRACE("pointer X "+pointer[i].GetX());
//		}
//		
//		for(int i=0; i < pointer.length; i++)
//		{
//			engine.attachParent(bg_pointer, pointer[i]);
//			engine.attachParent(bg_pointer, hover_pointer[i]);
//			
//			if(i > 0 )
//			{
//				hover_pointer[i].theSprite().setVisible(false);
//			}
//			
//		}
//	}
	

	static void attachDisplayPlayer(int ind1, int ind2)
	{
		bg_pointer.DetachSelf();
		
		for(int i =0; i < pointer.length; i++)
		{
			pointer[i].DetachSelf();
			hover_pointer[i].DetachSelf();
		}
		
	
		
	}
	
	static void detachDisplayAllPlayer()
	{
		
			for(int j=0; j < spr_unlock_player.length; j++)
			{
				spr_unlock_player[j].theSprite().setVisible(false);
			}
			
			for(int j=0; j < spr_lock_player.length; j++)
			{
				spr_lock_player[j].theSprite().setVisible(false);
			}
		
	}
	
	static void attachDisplayPlayer(ASprite[] spr_lock_or_unlock)
	{
		
		for(int j=0; j < spr_lock_or_unlock.length; j++)
		{
			spr_lock_or_unlock[j].theSprite().setVisible(true);
			if(spr_lock_or_unlock == spr_unlock_player)
			spr_lock_or_unlock[j].theSprite().setAlpha(1f);
		}
		
	}
	
	static void detachDisplayPlayer(ASprite[] spr_lock_or_unlock)

	{

			for(int j=0; j < spr_lock_or_unlock.length; j++)
			{
				
				spr_lock_or_unlock[j].theSprite().setVisible(false);
			}
		
	}
	
	static void visibleReview(int i, int j)
	{
		rec.theRect().setVisible(true);
		bg_review.theSprite().setVisible(true);
		btn_cancel.theSprite().setVisible(true);
		
	
		btn_pilih.theSprite().setVisible(true);
		
		
		txt_review_gasing.setText(iGameDefines.STRING_REVIEW_GASING[i][j]);
	
	}
	
	static void notVisibleRiview()
	{
		rec.theRect().setVisible(false);
		bg_review.theSprite().setVisible(false);
		btn_cancel.theSprite().setVisible(false);
		btn_pilih.theSprite().setVisible(false);
	
	}
	
	static void attachAllReview(GameEngine engine, AScene aScene)
	{
		bg_review.theSprite().detachChildren();
		engine.SceneAttach(aScene, bg_review);
		engine.attachParent(bg_review, btn_cancel);
		engine.attachParent(bg_review, btn_pilih);
		engine.attachParent(bg_review, txt_review_gasing);
				
		bg_review.theSprite().setVisible(false);
		btn_cancel.theSprite().setVisible(false);
		btn_pilih.theSprite().setVisible(false);
		
	}
	
	static void detachReview()
	{
		rec.theRect().detachSelf();
		bg_review.DetachSelf();
		btn_cancel.DetachSelf();
		btn_pilih.DetachSelf();
		txt_review_gasing.theText().detachSelf();
	}
	

	public void Touch(TouchEvent pSceneTouchEvent, ITouchArea pTouchArea,
			float pTouchAreaLocalX, float pTouchAreaLocalY)
	{
		if(pSceneTouchEvent.isActionUp() && pTouchArea.equals(btn_cancel.theSprite()) 
				&& btn_cancel.theSprite().isVisible())
		{
			
//			notVisibleRiview();
//			sfx_No.Play();
		}
		
				
		if(pSceneTouchEvent.isActionUp() && pTouchArea.equals(btn_pilih.theSprite())
				&& btn_pilih.theSprite().isVisible())
		{
			
//			engine.SetNextMessageState(engine.NextMessageState());
			
			
		}		
	}
	
	private void attachSelectRival() 
	{
		title_player.theSprite().setVisible(false);
		title_player.theSprite().setVisible(false);
		btn_pilih.theSprite().setVisible(false);
		
		
	}
	

	private void visibleShop()
	{
		for(int i=0; i < iGameDefines.SPRITE_SHOP.length; i++)
		{
			spr_shop[i].theSprite().setVisible(true);
		}
		
		nama_gasing.theText().setVisible(false);
	}
	
	
	private void notVisibleShop()
	{
		for(int i=0; i < iGameDefines.SPRITE_SHOP.length; i++)
		{
			spr_shop[i].theSprite().setVisible(false);
		}
		
		nama_gasing.theText().setVisible(true);
	}
	
	public void chooseMode()
	{
		engine.SetNextMessageState(engine.NextMessageState());
		
		if(GameEngineConfiguration.ModeSelected == iGameDefines.MODE_SINGLE)
		{
			engine.SetNextGameState(iGameDefines.GAME_STATE_SELECT_RIVAL);
		}
		else if(GameEngineConfiguration.ModeSelected == iGameDefines.MODE_MULTI)
		{
			engine.SetNextGameState(engine.NextGameState());
		}
		else
		{
			engine.SetNextGameState(engine.NextGameState());
			engine.SetNextGameState(iGameDefines.GAME_STATE_SELECT_MAP);
		}
	}

	public void onClick(ClickDetector pClickDetector, int pPointerID,
			float pSceneX, float pSceneY)
	{
	
		for(int i=0; i < spr_unlock_player.length; i++)
		{
		
			if (Utils.isOnArea(pSceneX, pSceneY, spr_unlock_player[i].theSprite()) && menu_Scroll_unlock.getFocus() == i 
					&& spr_unlock_player[i].theSprite().isVisible())
			{
//				Utils.TRACE("Click"+i);
				visibleReview(0, i);
				
				if(BT_Server_Client.isBluetooth)
				{
					// kirim index munuju index musuh
					if(BT_Server_Client.isServer)
					{
						iServer_Data.INDEX_MC = i;
						engine.server_Client.sendMessage("MC," + i);	
					}
					else
					{
						iServer_Data.INDEX_RIVAL = i;
						engine.server_Client.sendMessage("RIVAL," + i);	
						
					}
				}
				else
				{
					iServer_Data.INDEX_MC = i;
				}
			}
					
			
		}
		
		if(Utils.isOnArea(pSceneX, pSceneY, bg_review.theSprite(), btn_cancel.theSprite()) && btn_cancel.theSprite().isVisible())
		{
			notVisibleRiview();
			sfx_No.Play();
		}
		
				
		if(Utils.isOnArea(pSceneX, pSceneY, bg_review.theSprite(), btn_pilih.theSprite()) && btn_pilih.theSprite().isVisible())
		{
			if(BT_Server_Client.isBluetooth)
			{
				// pengecekan sudah saling memilih

				System.out.println("State_Select_Player.onClick()");
				if(BT_Server_Client.isServer)
				{
					engine.SetNextMessageState(0);
					engine.SetNextGameState(iGameDefines.GAME_STATE_SELECT_MAP);
				}				
				else
				{
					Utils.toast("Waiting Server...");
					BT_Server_Client.isClientWaiting = true;
					engine.server_Client.sendMessage("play,1");	
//					switchState(STATE_MENU_WAITING_CLIENT_SERVER);
				}
			}
			else
				engine.SetNextMessageState(engine.NextMessageState());
	
			
		}
		
		
		
		if( Utils.isOnArea(pSceneX, pSceneY, btn_menu[0].theSprite()) )
		{

			sfx_Yes.Play();
			btn_menu[0].setScale(1f);
			btn_menu[1].setScale(SCALE_MINI);
			btn_menu[2].setScale(SCALE_MINI);
			
			attachDisplayPlayer(spr_unlock_player);
			detachDisplayPlayer(spr_lock_player);
			notVisibleShop();
			
			nama_gasing.theText().setVisible(true);
		}
		if(Utils.isOnArea(pSceneX, pSceneY, btn_menu[1].theSprite()))
		{
		
			
			sfx_Yes.Play();
			btn_menu[0].setScale(SCALE_MINI);
			btn_menu[1].setScale(1f);
			btn_menu[2].setScale(SCALE_MINI);
			
			attachDisplayPlayer(spr_lock_player);
			detachDisplayPlayer(spr_unlock_player);
			notVisibleRiview();
			notVisibleShop();
			
			nama_gasing.theText().setVisible(false);
			
			notVisibleRiview();
		}
		if(Utils.isOnArea(pSceneX, pSceneY, btn_menu[2].theSprite()) && !Utils.isOnArea(pSceneX, pSceneY, btn_cancel.theSprite()))
		{

			sfx_Yes.Play();
			btn_menu[0].setScale(SCALE_MINI);
			btn_menu[1].setScale(SCALE_MINI);
			btn_menu[2].setScale(1f);
			
			detachDisplayPlayer(spr_lock_player);
			detachDisplayPlayer(spr_unlock_player);
			visibleShop();
			visibleShop();
			
		}

		
		
			
		
	}
		
	
	public void generateProfileGasing()
	{
		int sum_unlock = 0;
		int sum_lock = 0;
		
		for(int i=0; i < iServer_Data.isUnlockGasing.length; i++)
		{
			if(iServer_Data.isUnlockGasing[i])
			{
				sum_unlock+=1;
			}
			else
			{
				sum_lock+=1;
			}
		}
		
		Utils.TRACE("sum lock" +sum_lock);
		Utils.TRACE("sum unlock" +sum_unlock);
		spr_unlock_player = new ASprite[sum_unlock];
		spr_lock_player = new ASprite[sum_lock];
		
		for(int i=0; i < iServer_Data.isUnlockGasing.length; i++)
		{

			if(iServer_Data.isUnlockGasing[i])
			{
				spr_unlock_player[i] = spr_player[i];
				Utils.TRACE("unlock "+i);
			}
			else
			{
				Utils.TRACE("lock "+i);
				spr_lock_player[i-sum_unlock] = spr_player[i];
				
			}	
		}
		
		menu_Scroll_unlock = new Menu_Scroll(engine, sfx_slide.theSound(), State_Main_Activity.CAMERA_WIDTH / 3, spr_unlock_player);
		menu_Scroll_lock = new Menu_Scroll(engine, sfx_slide.theSound(), State_Main_Activity.CAMERA_WIDTH / 3, spr_lock_player);
		
		
		
	}


	private void attchShop() {
		
		for(int i=0; i< iGameDefines.SPRITE_SHOP.length; i++)
		{
			engine.SceneAttach(aScene, spr_shop[i]);
			spr_shop[i].theSprite().setVisible(false);
			
			if(iServer_Data.poin > iGameDefines.HARGA[i])
			{
				spr_shop[i].theSprite().setAlpha(1f);
			}
			else
			{
				spr_shop[i].theSprite().setAlpha(0.5f);
			}

		}
	}
	
	public static void attachPoint(GameEngine engine, AScene aScene)
	{
		engine.SceneAttach(aScene, img_point);
	
		txt_point.theText().setPosition(img_point.GetX() + img_point.theSprite().getWidth() + Utils.GetRatioWidth(10), 13); 
		txt_point.theText().setText(String.valueOf(iServer_Data.poin));
	
		txt_point.theText().setColor(Color.YELLOW);
		engine.SceneAttach(aScene, txt_point);
		
	}

	static void attachIcon(GameEngine engine, AScene aScene) {
		
		for(int i=0; i < spr_unlock_player.length; i++)
		{
			engine.SceneAttach(aScene, icon_player[i]);
			icon_player[i].theSprite().setVisible(false);
		}
	}
	
	static void detachIcon()
	{
		for(int i=0; i < spr_unlock_player.length; i++)
		{
			icon_player[i].DetachSelf();
		}
	}
	
	

	
}
